package picture.dao;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import MyDaily.pojo.Picture;

/**
 * Servlet implementation class PiceterServlet
 */
@WebServlet("/PiceterServlet")
public class PiceterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PiceterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取请求和响应的编码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		//从seesion中获取用户名进行模糊查询
		HttpSession session = request.getSession();
		String name = (String) session.getAttribute("name");
		//调用查询方法
		picture picture = new picture();
		List<Picture> pList = picture.Queryimg(name);
		if (pList.size() > 0) {
			request.setAttribute("list", pList);
			request.getRequestDispatcher("photo.jsp").forward(request, response);
		}else if(pList == null) {
			request.getRequestDispatcher("photo.jsp").forward(request, response);
		}
	}

}
